package cn.dujc.superkid.activities;

import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ImageView;

import java.util.ArrayList;

import cn.dujc.core.ui.BaseActivity;
import cn.dujc.superkid.R;
import cn.dujc.superkid.adapter.MyPagerAdapter;
import cn.dujc.superkid.fragment.start.AllFragment;
import cn.dujc.superkid.fragment.start.MonthFragment;
import cn.dujc.superkid.fragment.start.TotalFragment;
import cn.dujc.superkid.fragment.start.Weekfragment;

public class StartActivity extends BaseActivity {

    private TabLayout mTabLayout;
    private ViewPager mViewPager;

    @Override
    public int getViewId() {
        return R.layout.activity_start;
    }

    @Override
    public void initBasic(Bundle savedInstanceState) {
        setTitle("星星榜");
        initView(); // 初始化控件
        initViewPager(); // 初始化ViewPager
    }

    private void initViewPager() {
        // 创建一个集合,装填Fragment
        ArrayList<Fragment> fragments = new ArrayList<>();
        // 装填
        fragments.add(new Weekfragment());
        fragments.add(new MonthFragment());
        fragments.add(new TotalFragment());
        fragments.add(new AllFragment());
        // 创建ViewPager适配器
        MyPagerAdapter myPagerAdapter = new MyPagerAdapter(getSupportFragmentManager());
        myPagerAdapter.setFragments(fragments);
        // 给ViewPager设置适配器
        mViewPager.setAdapter(myPagerAdapter);
        // TabLayout 指示器 (记得自己手动创建4个Fragment,注意是 app包下的Fragment 还是 V4包下的 Fragment)
        mTabLayout.addTab(mTabLayout.newTab());
        mTabLayout.addTab(mTabLayout.newTab());
        mTabLayout.addTab(mTabLayout.newTab());
        mTabLayout.addTab(mTabLayout.newTab());
        // 使用 TabLayout 和 ViewPager 相关联
        mTabLayout.setupWithViewPager(mViewPager);
        // TabLayout指示器添加文本
        mTabLayout.getTabAt(0).setText("周排行");
        mTabLayout.getTabAt(1).setText("月排行");
        mTabLayout.getTabAt(2).setText("总排行");
        mTabLayout.getTabAt(3).setText("封神榜");
    }
    /**
     * 初始化控件
     */
    private void initView() {
        mTabLayout = (TabLayout)findViewById(R.id.starttablayout);
        mViewPager = (ViewPager)findViewById(R.id.startviewpager);
    }


}
